home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / HyperCard CTB Toolkit 1.0b2 / Source Code / CTBSendString.p < prev    next >
Encoding:
Text File  |  1995-02-07  |  2.0 KB  |  92 lines  |  [TEXT/MPS ]

  1. (*
  2.     CTBSendString string[,eom] -- Send a string out the current connection. If the eom parameter is
  3.         present and non-empty, then set the end-of-message bit when sending.
  4.  
  5.     To compile and link this file using Macintosh Programmer's Workshop,
  6.  
  7.         pascal -w CTBSendString.p
  8.         link -m ENTRYPOINT -o HyperCommands -rt XCMD=2754 -sn Main=CTBSendString ∂
  9.             CTBSendString.p.o "{MPW}"Libraries:interface.o "{MPW}"Libraries:Libraries:HyperXLib.o
  10.  
  11.     © Copyright 1990 by Apple Computer, Inc.
  12.  
  13.     Initial coding 2/90 by Harry R. Chesley.
  14. *)
  15.  
  16. {$R-}
  17.  
  18. {$S CTBSendString }     { Segment name must be the same as the command name. }
  19.  
  20. unit DummyUnit;
  21.  
  22. interface
  23.  
  24. uses MemTypes, QuickDraw, OSIntf, ToolIntf, CTBUtils, FTIntf, CMIntf, TMIntf, CRMIntf, HyperXCmd;
  25.  
  26. procedure EntryPoint(paramPtr: XCmdPtr);
  27.     
  28. implementation
  29.  
  30. procedure CTBSendString(paramPtr: XCmdPtr); forward;
  31.  
  32. procedure EntryPoint(paramPtr: XCmdPtr);
  33.  
  34.     begin
  35.         CTBSendString(paramPtr);
  36.     end;
  37.  
  38. procedure CTBSendString(paramPtr: XCmdPtr);
  39.  
  40.     {$I CTBUtil.inc}
  41.  
  42.     var i: integer;
  43.         flags: CMFlags;
  44.         p: Ptr;
  45.         l: longInt;
  46.         h: Handle;
  47.         err: CMErr;
  48.  
  49.     procedure Fail(errMsg: Str255); { set theResult and quit }
  50.         begin
  51.             paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
  52.             exit(CTBSendString);
  53.         end;
  54.  
  55.     begin
  56.         { Check the parameter count. }
  57.         i := paramPtr^.paramCount;
  58.         if (i = 0) or (i > 2) then Fail('Invalid parameter count');
  59.  
  60.         { Check for an empty string being sent. }
  61.         if not ParmPresent(1) then exit(CTBSendString);
  62.         h := paramPtr^.params[1];
  63.  
  64.         { Make sure the Comm Toolbox is here. }
  65.         CTBReady;
  66.         { And so is a connection tool. }
  67.         EnsurePresent(connectionTool);
  68.         { And the connection is open. }
  69.         EnsureOpen;
  70.  
  71.         { Figure the EOM flag setting. }
  72.         if ParmPresent(2) then flags := cmFlagsEOM
  73.         else flags := 0;
  74.  
  75.         { Count the number of bytes to be sent. }
  76.         l := 0;
  77.         p := h^;
  78.         while p^ <> 0 do
  79.             begin
  80.                 p := Ptr(ord4(p)+1);
  81.                 l := l+1;
  82.             end;
  83.  
  84.         { Send 'em. }
  85.         HLock(h);
  86.         err := CMWrite(Globals^^.connHand,h^,l,cmData,false,nil,-1,flags);
  87.         HUnlock(h);
  88.         if err <> noErr then Fail('Write failed');
  89.     end;
  90.  
  91. end.
  92.